home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
threads
/
ThreadsUIOTTY.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-24
|
3KB
|
116 lines
/* begincopyright
Copyright (c) 1988-1990 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* ThreadsUIOTTY.c
*
* Demers, July 16, 1990 3:21:58 pm PDT
*/
#include "xr/UIO.h"
#include "xr/UIOPrivate.h"
#include "xr/Errno.h"
#include "xr/GCVirtualDirty.h"
#include <sys/fcntl.h>
#include <sys/termios.h>
XR_Fildes
XR_TTYOpen(name, flags, cflag)
char *name;
unsigned flags;
unsigned cflag;
{
XR_Fildes fd = XR_nullFildes;
int ans;
unsigned iflag = 0;
unsigned oflag = 0;
struct termios cb;
fd = XR_Open(name, flags, 0666);
if( fd == XR_nullFildes ) goto Bad;
ans = XR_IOCtl4(fd, TCGETS, &cb, TRUE);
if( ans < 0 ) goto Bad;
if( cflag != 0 ) cb.c_cflag = cflag;
cb.c_iflag = iflag;
cb.c_oflag = oflag;
cb.c_lflag = 0;
cb.c_cc[VMIN] = 0;
cb.c_cc[VTIME] = 0;
ans = XR_IOCtl4(fd, TCSETS, &cb, TRUE);
if( ans < 0 ) goto Bad;
return fd;
Bad:
if( fd != XR_nullFildes ) {
int sav = XR_GetErrno();
(void) XR_Close(fd);
XR_SetErrno(sav);
}
return (-1);
}
static XR_FDE_FDC_WORKER(XR_TTYReadWorker)
{
int ans;
XR_ProtectSysCall(x1,x2);
ans = read(fdc->fdc_index, x1, x2);
XR_UnprotectSysCall();
if( ans == 0 ) {
XR_SetErrno(EWOULDBLOCK);
return (-1);
}
return(ans);
}
int
XR_TTYRead(fildes, buf, nBytes)
XR_Fildes fildes;
XR_Pointer buf;
unsigned nBytes;
{
int n, nRead;
XR_UIOWaitReadyProc waitReadyProc;
nRead = 0;
for(
waitReadyProc = &XR_UIOIn0WaitReadyProc;
;
waitReadyProc = &XR_UIOIn1WaitReadyProc
) {
n = XR_UIODoWithFDEAndFDC(
fildes,
waitReadyProc,
XR_TTYReadWorker,
((unsigned)(buf+nRead)),
((unsigned)(nBytes-nRead))
);
if( (n <= 0) || ((nRead += n) >= nBytes) ) break;
}
if( n >= 0 ) return(nRead);
switch( XR_GetErrno() ) {
case EWOULDBLOCK:
case EAGAIN: /* System V version of EWOULDBLOCK */
if( nRead > 0 ) return(nRead);
break;
}
return(-1);
}